/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.config;

import java.io.*;
import java.util.*;

/**
 *
 * @author QuocThanh
 */
public class MySQLQuery {
    
    public enum QueryKey{
        SELECT_PHIEU,
        SELECT_ALL_PHIEU,
        SELECT_SOLUONG_PHIEU,
        SELECT_SOLUONG_PHIEU_TREN_TRANG,
        SELECT_ALL_PHIEU_TRANG_I,
        SELECT_ALL_PHIEU_DANHMUC,
        SELECT_ALL_PHIEU_DANHMUC_TRANG,
        TIMKIEM_TEN,
        TIMKIEM_TEN_PHANTRANG,
        INSERT_PHIEU,
        DELETE_PHIEU,
        UPDATE_PHIEU,
        UPDATE_SOLUONGTON_PHIEU,
               
        SELECT_ALL_HOADON,
        INSERT_HOADON,
        DELETE_HOADON,
        UPDATE_HOADON,
        
        SELECT_ALL_CHITIETHOADON,
        SELECT_ALL_MACHITIETHOADON,
        INSERT_CHITIETHOADON,
        DELETE_CHITIETHOADON,
        UDPATE_CHITIETHOADON,        
        
        SELECT_ALL_PHIEUNHAP,
        INSERT_PHIEUNHAP,
        DELETE_PHIEUNHAP,
        UPDATE_PHIEUNHAP,
        
        SELECT_ALL_CHITIETPHIEUNHAP,
        SELECT_ALL_MACHITIETPHIEUNHAP,
        INSERT_CHITIETPHIEUNHAP,
        DELETE_CHITIETPHIEUNHAP,
        UDPATE_CHITIETPHIEUNHAP,
        
        
        SELECT_ALL_NHACUNGCAP,
        INSERT_NHACUNGCAP,
        DELETE_NHACUNGCAP,
        UPDATE_NHACUNGCAP,        
        
        SELECT_ALL_DANHMUC,
        INSERT_DANHMUC,
        DELETE_DANHMUC,
        UPDATE_DANHMUC,
        
        SELECT_ALL_QUANTRI_PHANTRANG,
        SELECT_ALL_DANHMUC_PHANTRANG,
        SELECT_ALL_NCC_PHANTRANG,
        SELECT_ALL_PHIEU_PHANTRANG,
        SELECT_ALL_KHACHHANG_PHANTRANG,
        SELECT_ALL_DONDATHANG_PHANTRANG,
        SELECT_ALL_CTDONDATHANG_PHANTRANG,
        SELECT_ALL_HINHCTPHIEU_PHANTRANG,
        SELECT_ALL_NHATKYMOIBAN_PHANTRANG,
        SELECT_ALL_NHATKYTICHLUYDIEM_PHANTRANG,
        SELECT_ALL_THAMSO_PHANTRANG,
        SELECT_ALL_TINHTRANGPHIEU_PHANTRANG,
        SELECT_ALL_TINHTRANGDONHANG_PHANTRANG
    }
    
    private ArrayList<Vector> DSQuery;
    public MySQLQuery() {
        this.DSQuery=new ArrayList<Vector>();
    }

    public ArrayList<Vector> getDSQuery() {
        return DSQuery;
    }

    public void setDSQuery(ArrayList<Vector> DSQuery) {
        this.DSQuery = DSQuery;
    }
    
   public void Read(String table) throws FileNotFoundException, IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("MySQLQuery.txt")));
        String line="";
        
        do {
             line = br.readLine(); 
               if(line!=null && line.trim().startsWith("["+table+"]")){
                    line = br.readLine();
                    while(line!=null &&!line.trim().startsWith("}"))
                    {
                        line = br.readLine();
                        if(line!=null &&!line.trim().startsWith("--")){
                            String[] temp=line.trim().split("=>");
                            if(temp.length>1){
                                Vector vt=new Vector();
                                for (int i = 0; i < temp.length; i++) {
                                     vt.add(temp[i]);                     
                                }
                                this.DSQuery.add(vt);
                            }
                            

                        }  
                    }
                    break;
                }
       } while (line!=null);      
        
       
        br.close();
   }
    
   public String GetQuery(QueryKey queryKey){
       for (int i = 0; i < this.DSQuery.size(); i++) {
           if(queryKey.toString().equals(this.DSQuery.get(i).get(0).toString().trim())) {
               return this.DSQuery.get(i).get(1).toString().trim();
           }
       }
       return "";
   } 
    
    
}
